package com.niit.yhserver.service.impl;


import com.niit.yhpojo.dto.MenuDTO;
import com.niit.yhpojo.entity.Menu;
import com.niit.yhserver.mapper.MenuMapper;
import com.niit.yhserver.service.MenuService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuMapper menuMapper;

    @Override
    public List<Menu> getAllMenu() {

        return menuMapper.getAllMenu();
    }


    @Override
    public Menu getMenuById(int id) {

        return menuMapper.getMenuById(id);
    }

    @Override
    public int addMenu(MenuDTO menuDTO) {

        Menu menu = new Menu();
        //对象属性拷贝
        BeanUtils.copyProperties(menuDTO, menu);

        return menuMapper.addMenu(menu);
    }

    @Override
    public void updateMenu(MenuDTO menuDTO) {

        Menu menu = new Menu();
        BeanUtils.copyProperties(menuDTO, menu);
        menuMapper.updateMenu(menu);
    }

    @Override
    public void deleteMenuById(Integer id) {

        menuMapper.deleteMenu(id.intValue());
    }
}